package cn.xscrum.demo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.demo.domain.CityTrackList;
import cn.xscrum.demo.service.ICityTrackListService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * huanlistController
 *
 * @author xscrum
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/demo/huanlist")
public class CityTrackListController extends BaseController
{
    private String prefix = "demo/huanlist";

    @Autowired
    private ICityTrackListService cityTrackListService;

    @RequiresPermissions("demo:huanlist:view")
    @GetMapping()
    public String huanlist()
    {
        return prefix + "/huanlist";
    }

    /**
     * 查询huanlist列表
     */
    @RequiresPermissions("demo:huanlist:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CityTrackList cityTrackList)
    {
        startPage();
        List<CityTrackList> list = cityTrackListService.selectCityTrackListList(cityTrackList);
        return getDataTable(list);
    }

    /**
     * 导出huanlist列表
     */
    @RequiresPermissions("demo:huanlist:export")
    @Log(title = "huanlist", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CityTrackList cityTrackList)
    {
        List<CityTrackList> list = cityTrackListService.selectCityTrackListList(cityTrackList);
        ExcelUtil<CityTrackList> util = new ExcelUtil<CityTrackList>(CityTrackList.class);
        return util.exportExcel(list, "huanlist");
    }

    /**
     * 新增huanlist
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存huanlist
     */
    @RequiresPermissions("demo:huanlist:add")
    @Log(title = "huanlist", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CityTrackList cityTrackList)
    {
        return toAjax(cityTrackListService.insertCityTrackList(cityTrackList));
    }

    /**
     * 修改huanlist
     */
    @GetMapping("/edit/{no}")
    public String edit(@PathVariable("no") Long no, ModelMap mmap)
    {
        CityTrackList cityTrackList = cityTrackListService.selectCityTrackListById(no);
        mmap.put("cityTrackList", cityTrackList);
        return prefix + "/edit";
    }

    /**
     * 修改保存huanlist
     */
    @RequiresPermissions("demo:huanlist:edit")
    @Log(title = "huanlist", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CityTrackList cityTrackList)
    {
        return toAjax(cityTrackListService.updateCityTrackList(cityTrackList));
    }

    /**
     * 删除huanlist
     */
    @RequiresPermissions("demo:huanlist:remove")
    @Log(title = "huanlist", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cityTrackListService.deleteCityTrackListByIds(ids));
    }
}
